<?php

namespace App\Service\Model;


class Agency extends \Eloquent
{
    const LEVEL_ONE  = 1;//一级代理
    const LEVEL_TWO  = 2;//二级代理
   
    /**
     * The database used by the model.
     *
     * @var string
     */
    protected $table = 'agency';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable= ['tel','password','name','invite_code','parent_id','level','ratio'];
    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['password'];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [

    ];

    public function __construct(array $attributes = []){
        parent::__construct($attributes);
    }


    /**
     * Undocumented function
     *
     * @return void
     */
    public static function getFirstLevelAgency(){
        $agency = self::where('parent_id',0)->select(['id','tel','name'])->get();
        $res    = null;
        foreach($agency as $item){
            $res[$item['id']] = $item['name'].'-'.$item['tel'];
        }
        $first = [0 => '一级代理'];
        if($res){
            return array_merge($first,$res);
        }else{
            return $first;
        }
    }


}
